# Generated by Django 5.0.6 on 2024-06-05 07:21

import django.db.models.deletion
import django.db.models.expressions
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Groups',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('create_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('update_at', models.DateTimeField(auto_now=True)),
                ('group', models.CharField(max_length=100, unique=True, verbose_name='Группа')),
            ],
            options={
                'verbose_name': 'Группы сотрудников',
                'verbose_name_plural': 'Группы сотрудников',
            },
        ),
        migrations.CreateModel(
            name='Product',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('create_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('update_at', models.DateTimeField(auto_now=True)),
                ('name', models.CharField(max_length=100, unique=True, verbose_name='Название продукта')),
                ('warehouse', models.DecimalField(decimal_places=2, default=0.0, max_digits=8, verbose_name='Остаток на складе')),
            ],
            options={
                'verbose_name': 'Продукты',
                'verbose_name_plural': 'Продукты',
            },
        ),
        migrations.CreateModel(
            name='ProductSection',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('create_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('update_at', models.DateTimeField(auto_now=True)),
                ('name', models.CharField(max_length=100, unique=True, verbose_name='Название группы продуктов')),
            ],
            options={
                'verbose_name': 'Группы продуктов',
                'verbose_name_plural': 'Группы продуктов',
            },
        ),
        migrations.CreateModel(
            name='Contract',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('create_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('update_at', models.DateTimeField(auto_now=True)),
                ('organization_name', models.TextField(max_length=500, verbose_name='Организация')),
                ('contract_number', models.CharField(max_length=100, verbose_name='Номер договора')),
                ('is_closed', models.BooleanField(default=False, verbose_name='Расторгнут')),
                ('start_date', models.DateField(verbose_name='Дата начала договора')),
                ('end_date', models.DateField(verbose_name='Дата окончания договора')),
            ],
            options={
                'verbose_name': 'Договора',
                'verbose_name_plural': 'Договора',
                'unique_together': {('contract_number', 'start_date')},
            },
        ),
        migrations.CreateModel(
            name='ContractProduct',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('create_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('update_at', models.DateTimeField(auto_now=True)),
                ('oms_full', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='ОМС по контракту')),
                ('oms_balance', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='ОМС остаток')),
                ('oms_percent', models.GeneratedField(db_persist=True, expression=django.db.models.expressions.CombinedExpression(django.db.models.expressions.CombinedExpression(models.F('oms_balance'), '/', models.F('oms_full')), '*', models.Value(100)), output_field=models.PositiveIntegerField(), verbose_name='ОМС остаток в %')),
                ('ob_full', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='ОБ по контракту')),
                ('ob_balance', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='ОБ остаток')),
                ('ob_percent', models.GeneratedField(db_persist=True, expression=django.db.models.expressions.CombinedExpression(django.db.models.expressions.CombinedExpression(models.F('ob_balance'), '/', models.F('ob_full')), '*', models.Value(100)), output_field=models.PositiveIntegerField(), verbose_name='ОБ остаток в %')),
                ('pd_full', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='ПД по контракту')),
                ('pd_balance', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='ПД остаток')),
                ('pd_percent', models.GeneratedField(db_persist=True, expression=django.db.models.expressions.CombinedExpression(django.db.models.expressions.CombinedExpression(models.F('pd_balance'), '/', models.F('pd_full')), '*', models.Value(100)), output_field=models.PositiveIntegerField(), verbose_name='ПД остаток в %')),
                ('contract', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='orders.contract', verbose_name='Договор')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='orders.product', verbose_name='Продукт')),
            ],
            options={
                'verbose_name': 'Лимиты по продуктам',
                'verbose_name_plural': 'Лимиты по продуктам',
            },
        ),
        migrations.AddField(
            model_name='product',
            name='product_section',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='orders.productsection', verbose_name='Группа продуктов'),
        ),
        migrations.CreateModel(
            name='StockRecord',
            fields=[
                ('create_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('update_at', models.DateTimeField(auto_now=True)),
                ('id', models.AutoField(primary_key=True, serialize=False, verbose_name='Номер документа')),
                ('document_date', models.DateField(verbose_name='Дата')),
                ('incoming_weight', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='Входящий вес')),
                ('outgoing_weight', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='Исходящий вес')),
                ('stock_code', models.CharField(choices=[('oms', 'ОМС'), ('ob', 'ОБ'), ('pd', 'ПД')], max_length=100, verbose_name='Код оплаты')),
                ('contract_product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='orders.contractproduct', verbose_name='Договор')),
            ],
            options={
                'verbose_name': 'Документы на списание',
                'verbose_name_plural': 'Документы на списание',
            },
        ),
        migrations.CreateModel(
            name='Users',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('create_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('update_at', models.DateTimeField(auto_now=True)),
                ('fam', models.CharField(max_length=50, verbose_name='Фамилия')),
                ('im', models.CharField(max_length=50, verbose_name='Имя')),
                ('ot', models.CharField(default='', max_length=50, verbose_name='Отчество')),
                ('dolzh', models.CharField(max_length=50, verbose_name='Должность')),
                ('groups', models.ManyToManyField(to='orders.groups', verbose_name='Группы')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Пользователь')),
            ],
            options={
                'verbose_name': 'Сотрудники',
                'verbose_name_plural': 'Сотрудники',
            },
        ),
    ]
